package cy.action;

import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;

import cy.util.ImageUtils;

@ParentPackage("json-default")
@Namespace("/")
@Action(value = "imageAction")
@Result(name="success",type="stream",params={"inputName","is"})
@Scope("prototype") 
public class ImageAction extends BaseAction {
	private InputStream is;
	public String execute() {
		Map<String, BufferedImage> map = ImageUtils.getImage();
		String code = map.keySet().iterator().next();
		session.put("code", code);
		BufferedImage image = map.get(code);
		try {
			is = ImageUtils.imageToStream(image);
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		return "success";
	}

	public InputStream getIs() {
		return is;
	}

	public void setIs(InputStream is) {
		this.is = is;
	}

}
